<template>
    <div class="employee-container">
      <el-row>
        <el-breadcrumb separator="/">
          <el-breadcrumb-item>首页</el-breadcrumb-item>
          <el-breadcrumb-item>基础信息管理</el-breadcrumb-item>
          <el-breadcrumb-item>员工信息</el-breadcrumb-item>
        </el-breadcrumb>
      </el-row>
      <el-row>
        <el-form label-width="80px">
          <el-row>
            <el-col :span="8" style="margin-top: 10px">
              <el-form-item label="姓名" label-width="80px">
                <el-input style="height: 8%"></el-input>
              </el-form-item>
            </el-col>
            <el-col>
              <el-col :span="8"style="margin-top: 10px">
                <el-form-item label="所在部门"label-width="80px">
                </el-form-item>
              </el-col>
              <el-col :span="8"style="margin-top: 10px">
                <el-form-item>
                  <el-button type="success"style="background-color: cornflowerblue">搜索</el-button>
                </el-form-item>
              </el-col>
            </el-col>
          </el-row>
        </el-form>
      </el-row>
      <el-row>
<div>
  <el-button-group>
    <el-button @click="btnAddClick"type="primary"icon="el-icon-edit">添加</el-button>
    <el-button type="primary"icon="el-icon-share">修改</el-button>
    <el-button type="primary"icon="el-icon-delete">删除</el-button>
  </el-button-group>
</div>

        <el-table
                  :data="tableData"
                  border
                  stripe
                  style="width: 100%">
          <el-table-column
            prop="name"
            label="姓名"
            width="180">
          </el-table-column>
        <el-table-column
          prop="gender"
          label="性别">
        </el-table-column>
        </el-table>
        <el-pagination
          small
          layout="prew,pager,next"
          :total="50">
        </el-pagination>
      </el-row>
<el-dialog
title="员工添加"
:visible.sync="dialogVisible"
width="30%"
:before-close="handleClose">
  <el-form>
    <el-form-item label-width="80px"label="员工姓名">
      <el-input v-model="employee.name"/>
    </el-form-item>
  </el-form>
  <span slot="footer"class="dialog-footer">
    <el-button @click="dialogVisible=false">取消</el-button>
    <el-button type="primary"@click="sumbmitHandle">确定</el-button>
  </span>
</el-dialog>
    </div>
</template>

<script>
  export default {
    name:"Employee",data(){
      return{
        tableData: []
      }
    },mounted() {
      var_this=this;
      this.axios({
        url:'http://localhost:3000/employee/list',
        method:'get'
      }),then(function (res) {
        _this.tableData=res.data;
      })
    },methods:{
      btnAddClick(){
        this.dialogVisible=true;
      },
      handleClose(){
        this.dialogVisible=false;
      },sumbmitHandle(){
        var_this=this;
        this.axios({
          url:'http://127.0.0.1:3000/emp/add',
          method: 'get',
          params:{
            name:this.employee.name
          }
        }).then(function (res) {
          if (res.data.flag){
            _this.tableData=res.data.emps;
            _this.$message('添加成功')
            _this.dialogVisible=false;
          }else {
            alert('添加失败')
          }
        })
      }
    }
  }

</script>

<style scoped>

</style>
